# -*- coding: utf-8 -*-
"""
Created on Sun Jun 10 14:14:13 2012

@author: nzhao
"""

from traits.api import HasTraits, Array
from traitsui.api import View, Item, ArrayEditor

import numpy as np

Default_Axis_X = np.array([1.0, 0.0, 0.0])
Default_Axis_Y = np.array([0.0, 1.0, 0.0])
Default_Axis_Z = np.array([0.0, 0.0, 1.0])

class CoordinateSystem(HasTraits):
    x_axis = Array(editor = ArrayEditor(width = 150, format_str = '%8.3f'))
    y_axis = Array(editor = ArrayEditor(width = 150, format_str = '%8.3f'))
    z_axis = Array(editor = ArrayEditor(width = 150, format_str = '%8.3f'))
    
    def __init__(self, x_axis = Default_Axis_X, y_axis=Default_Axis_Y, z_axis=Default_Axis_Z):
        self.x_axis, self.y_axis, self.z_axis = x_axis, y_axis, z_axis
    
    def _vector(self, comp):
        x, y, z = comp
        return x * self.x_axis + y * self.y_axis + z * self.z_axis
    def _component(self, vector):
        return np.array([
                    np.dot(self.x_axis, vector),\
                    np.dot(self.y_axis, vector),\
                    np.dot(self.z_axis, vector)
            ])
    
    traits_view = View( Item('x_axis'),
                        Item('y_axis'),
                        Item('z_axis'),
                       )
